from stgm import *;
from subprocess import call;

g = Graph();
a = Node("A");
b = Node("B");
z1 = Node("Z1");
z2 = Node("Z2");

g.addnode(a, [], [0]);
aP = [0,0];
g.addnode(b, [a], [aP[0],aP[1]]); #[F, T]
g.addnode(a, [b], [aP[0],aP[1]]); #[F, T]
#g.addnode(z1, [a], [0.5, 0.5]); #[F, T]
#g.addnode(z2, [b], [0.5, 0.5]); #[F, T]
g.setup();

#g.addobs(b, False);
#g.addobs(e, True);


print g.priorprob([a,b]);
#print g.postprob([a,b]);
print "";
print "P(~A,~B):", (1-aP[0])*(1-g.priorprob([b])[0]);
print "P(~A, B):", (1-aP[1])*g.priorprob([b])[0];
print "P( A,~B):", aP[0]*(1-g.priorprob([b])[0]);
print "P( A, B):", aP[1]*g.priorprob([b])[0];
#print aP[1]*g.priorprob([a])[0];
#print aP[1]*g.priorprob([b])[0];
#print g.priorprob([a,b,z1,z2]);
#print g.postprob([a,b,z1,z2]);


#g.write2dot(fname='./InferenceBB/InfBB-graph.dot');
#call(['dot', '-Tpdf', './InferenceBB/InfBB-graph.dot', '-o', './InferenceBB/InfBB-graph.pdf']);
#call(['evince', './InferenceBB/InfBB-graph.pdf']);